package com.zzw.bridge.common.utils;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.zzw.bridge.common.exception.ServerException;
import org.springframework.util.CollectionUtils;

import java.util.Collection;


/**
 * 校验工具类
 */
public class AssertUtils {

	public static void isBlank (String str, String variable) {
		if (StrUtil.isBlank(str)) {
			throw new ServerException(variable + "不能为空");
		}
	}

	public static void isArgsNull (Object object, String variable) {
		if (object == null) {
			throw new ServerException(variable + "不能为空");
		}
	}

	public static void isNull (Object object, String variable) {
		if (object == null) {
			throw new ServerException(variable);
		}
	}

	public static void isArrayEmpty (Object[] array, String variable) {
		if (ArrayUtil.isEmpty(array)) {
			throw new ServerException(variable + "不能为空");
		}
	}

	/**
	 * 条件判断
	 *
	 * @param flag 条件
	 * @param msg  抛出信息
	 */
	public static void isTrue (boolean flag, String msg) {
		if (flag) {
			throw new ServerException(msg);
		}
	}

	public static void isNotNull (Object obj, String msg) {
		if (obj != null) {
			throw new ServerException(msg);
		}
	}

	public static void isArgsCollectNull (Collection<?> list, String msg) {
		if (CollectionUtils.isEmpty(list)) {
			throw new ServerException(msg + "不能为空 ");
		}
	}

	public static void isCollectNull (Collection<?> basePoints, String msg) {
		if (CollectionUtils.isEmpty(basePoints)) {
			throw new ServerException(msg);
		}
	}

}
